<html>
<head><meta charset="utf-8"><title>How to get `Out-Dir` · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html">How to get `Out-Dir`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190023792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190023792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190023792">(Mar 08 2020 at 18:52)</a>:</h4>
<p>In <a href="https://github.com/rust-lang/cargo/issues/7622" target="_blank" title="https://github.com/rust-lang/cargo/issues/7622">cargo#7622</a>,  <span class="user-mention" data-user-id="133169">@matklad</span> introduce a new build-script-executed JSON message <code>out-dir</code>. However,  calling <code>cargo metadata</code>solely will not include these data because they are compiler-messages. So do we want to run <code>cargo check</code> at  RA server start up to get these messages explicitly?  Or there are some magical sub-command in cargo which would build the build-scripts only, but not all deps ?</p>



<a name="190024027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190024027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190024027">(Mar 08 2020 at 18:59)</a>:</h4>
<p>Yeah, I think we need to run <code>cargo-check</code>. Id started though with many<br>
just a way to manually specify <code>OUT_DIR</code> via config?</p>



<a name="190024383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190024383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190024383">(Mar 08 2020 at 19:10)</a>:</h4>
<blockquote>
<p>Or there are some magical sub-command in cargo which would build the build-scripts only, but not all deps ?</p>
</blockquote>
<p><span class="user-mention" data-user-id="133169">@matklad</span> has an issue currently open for approximately that <a href="https://github.com/rust-lang/cargo/issues/7178" target="_blank" title="https://github.com/rust-lang/cargo/issues/7178">https://github.com/rust-lang/cargo/issues/7178</a></p>



<a name="190024398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190024398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190024398">(Mar 08 2020 at 19:11)</a>:</h4>
<p>This is actually a pretty interesting question when you get into it: <code>cargo check</code> on an existing workspace (i.e. one that hasn't been cleaned) _won't recompile (recheck) dependencies_. So you won't even get to run dependencies' build scripts to get the build-script-executed message.</p>



<a name="190024795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190024795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190024795">(Mar 08 2020 at 19:23)</a>:</h4>
<p>I believe cargo replaces cached output of <a href="http://build.rs" target="_blank" title="http://build.rs">build.rs</a></p>



<a name="190024836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190024836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190024836">(Mar 08 2020 at 19:24)</a>:</h4>
<p>Correct, if the inputs to <a href="http://build.rs" target="_blank" title="http://build.rs">build.rs</a> are not changed, cargo won't rerun the <a href="http://build.rs" target="_blank" title="http://build.rs">build.rs</a></p>



<a name="190024893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190024893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190024893">(Mar 08 2020 at 19:26)</a>:</h4>
<p>I think the "best user experience" would be to have a persistent cache of dependencies' OUT_DIR to avoid the need to re-run build scripts on project load. Roughly:</p>
<ul>
<li>Check persistence cache.</li>
<li>
<p>If cache is present:</p>
<ul>
<li>
<p>If OUT_DIR exists:</p>
<ul>
<li>Use that OUT_DIR.</li>
</ul>
</li>
<li>
<p>Compilation cache has been cleared since last project launch.</p>
</li>
<li>Delete current persistence cache.</li>
</ul>
</li>
<li>
<p>If cache is not present (or was just deleted):</p>
<ul>
<li>Prompt user to check or build dependencies.</li>
<li>Convince cargo that the crates without a cached OUT_DIR are dirty and need recompile/recheck (when invoked through the LS)</li>
</ul>
</li>
<li>When user triggers a check or build through the LS:<ul>
<li>Use the build-script-executed message to persist the OUT_DIR.</li>
<li>Somehow mark build-script-free dependencies as not requiring the cached OUT_DIR.</li>
</ul>
</li>
</ul>



<a name="190025026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025026">(Mar 08 2020 at 19:31)</a>:</h4>
<p><a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed" target="_blank" title="https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed">Here's the docs for buildscript rerun-if-changed</a>. TL;DR: by default, buildscripts rerun if any file "in the package" changes. The buildscript can, however, request to be rerun on any closed set of file changes and any set of (non-cargo) environment variables.</p>



<a name="190025159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025159">(Mar 08 2020 at 19:35)</a>:</h4>
<p>There's also the issue I opened that's still open for adding OUT_DIR information to <code>cargo metadata</code>: <a href="https://github.com/rust-lang/cargo/issues/7546" target="_blank" title="https://github.com/rust-lang/cargo/issues/7546">https://github.com/rust-lang/cargo/issues/7546</a></p>



<a name="190025197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025197">(Mar 08 2020 at 19:36)</a>:</h4>
<p>But the current way it's accessible is purely through the build-script-executed message IIUC.</p>



<a name="190025250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025250">(Mar 08 2020 at 19:38)</a>:</h4>
<p>And ofc <code>cargo metadata</code> has less information than an actual build, so it can't really know the correct <code>OUT_DIR</code> (currently?) relies on target-specific information.</p>



<a name="190025599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025599">(Mar 08 2020 at 19:49)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> Sound reasonable. I would start from config.</p>



<a name="190025660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025660">(Mar 08 2020 at 19:50)</a>:</h4>
<p>Relevant snippets from IntelliJ IDEA:</p>
<p>On the "fetch and index dependencies" step, if the "run build scripts" experimental feature is enabled, run <code>cargo check</code> on the project and extract build script json outputs <a href="https://github.com/intellij-rust/intellij-rust/blob/8b3c4edc66774d3c94dfced742febfb23c56a706/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt#L94-L165" target="_blank" title="https://github.com/intellij-rust/intellij-rust/blob/8b3c4edc66774d3c94dfced742febfb23c56a706/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt#L94-L165">https://github.com/intellij-rust/intellij-rust/blob/8b3c4edc66774d3c94dfced742febfb23c56a706/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt#L94-L165</a>  <br>
If I'm not mistaken that means that it doesn't actually get dependency build scripts if they've already been cached. However, I think this isn't a problem for IntelliJ Rust because I think IDEA caches indexing information?</p>



<a name="190025715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025715">(Mar 08 2020 at 19:52)</a>:</h4>
<p>I remember IntelliJ use build-plan ?</p>



<a name="190025794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20%60Out-Dir%60/near/190025794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20.60Out-Dir.60.html#190025794">(Mar 08 2020 at 19:55)</a>:</h4>
<p>Ah, sorry for typo. Cargo <strong>replays</strong> build output of cached bulid scripts: <a href="https://gist.github.com/matklad/a685495d4f67a17b62b29ac278af1afa" target="_blank" title="https://gist.github.com/matklad/a685495d4f67a17b62b29ac278af1afa">https://gist.github.com/matklad/a685495d4f67a17b62b29ac278af1afa</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>